package com.luxf.base.domainevent.utils;

import com.luxf.base.domainevent.constants.EventNoticeConstants;
import com.luxf.base.domainevent.model.DomainEventNotice;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import java.util.Optional;

/**
 * @author fast66
 * 2021-05-27 12:32
 **/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class EventNoticeUtils {

    public static String getMessageId(DomainEventNotice notice) {
        return notice.getHeader().get(EventNoticeConstants.MESSAGE_ID);
    }

    public static String getClassType(DomainEventNotice notice) {
        return notice.getHeader().get(EventNoticeConstants.CLASS_TYPE);
    }

    public static String getClassVersion(DomainEventNotice notice) {
        return notice.getHeader().get(EventNoticeConstants.CLASS_VERSION);
    }

    public static String getSource(DomainEventNotice notice) {
        return notice.getHeader().get(EventNoticeConstants.SOURCE_SERVICE);
    }

    public static Optional<String> getLocalUser(DomainEventNotice notice) {
        return Optional.ofNullable(notice.getHeader().get(EventNoticeConstants.HEADER_LOCAL_USER));
    }

    public static String getAggregateId(DomainEventNotice notice) {
        return notice.getHeader().get(EventNoticeConstants.AGGREGATE_ID);
    }
}
